package main

import (
	"blog2/handler"
	"blog2/util"

	"github.com/gin-gonic/gin"
)

func main() {
	util.InitLog("log")
	router := gin.Default()
	router.StaticFile("/favicon.ico", util.ProjectRootPath+"views/img/f.png")
	router.LoadHTMLFiles(util.ProjectRootPath+"views/login.html",
		util.ProjectRootPath+"views/publish_blog.html",
		util.ProjectRootPath+"views/blog_list.html")

	router.GET("/", func(ctx *gin.Context) { ctx.HTML(200, "index.html", nil) })
	router.GET("/login", func(ctx *gin.Context) { ctx.HTML(200, "login.html", nil) })
	router.GET("/publish", handler.PublishHTML)
	router.GET("/list", handler.BlogList)
	router.POST("/login/submit", handler.Login)
	router.POST("/register/submit", handler.Register)
	router.POST("/article/submit", handler.PublishBlog)
	router.GET("/articles/list", handler.GetBlogListByUid)
	router.POST("/article/:id/like", handler.AddBlogLikeToBlog)
	router.POST("/article/:id/favorite", handler.AddBlogFavoriteToBlog)
	router.POST("/article/:id/delete", handler.DelBlogByBlogId)
	router.POST("/article/:id/publishcomment", handler.PublishComment)
	router.Run("127.0.0.1:8866")
}

// import (
// 	"net/http"

// 	"github.com/gin-gonic/gin"
// )

// func main() {
// 	router := gin.Default()
// 	router.GET("/set-cookie", setCookieHandler)
// 	router.GET("/check-cookie", checkCookieHandler)
// 	router.Run(":8080")
// }

// func setCookieHandler(ctx *gin.Context) {
// 	//cookie := http.Cookie{Name: "test_cookie", Value: "12345", HttpOnly: true}
// 	ctx.SetCookie("test_cookie", "12345", 60, "/", "", false, true)
// 	ctx.JSON(http.StatusOK, gin.H{"message": "Cookie set successfully"})
// }

// func checkCookieHandler(ctx *gin.Context) {
// 	cookies := ctx.Request.Cookies()
// 	for _, cookie := range cookies {
// 		if cookie.Name == "test_cookie" {
// 			ctx.JSON(http.StatusOK, gin.H{"message": "Cookie exists", "cookie": cookie})
// 			return
// 		}
// 	}
// 	ctx.JSON(http.StatusNotFound, gin.H{"message": "Cookie not found"})
// }
